package com.danny.Controller;

import com.danny.mapper.GuestroomMapper;
import com.danny.pojo.Guestroom;
import com.danny.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class GuestroomController {
    @Autowired
    GuestroomMapper guestroomMapper;

    @GetMapping("/queryguestroom")
    public List<Guestroom> guestroom() {
        return guestroomMapper.queryAllGuestroom();
    }

    @GetMapping("/GuestroomSearch")
    public List<Guestroom> getGuestroom(String rtype, int page, int pageSize) {
        return guestroomMapper.queryGuestroomLimit(rtype, page, pageSize);
    }

    @GetMapping("/queryGuestroomLimit")
    public Map<String, Object> queryGuestroomLimit(int page, int pageSize) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg", "成功");
        map.put("data", guestroomMapper.queryGuestroomLimitBynoParam(page, pageSize));
        return map;
    }

    @GetMapping("/queryGuestHasInput")
    public List<Guestroom> queryLimitHasInput(String rtype, int page, int pageSize) {
        return guestroomMapper.queryGuestroomLimit(rtype, page, pageSize);

    }

    @GetMapping("/Guestroom")
    public List<Guestroom> Guestroom() {
        return guestroomMapper.queryGuestroom();
    }

    @GetMapping("/GuestroomPageCount")
    public int getGuestPageCount() {
        return guestroomMapper.GuestPageCount();

    }

    @GetMapping("/addGuestroom")
    public String addGuestroom(Guestroom guestroom) {
        if (guestroomMapper.addGuestroom(guestroom) != 0) {
            return "inserted";
        }
        return "error";
    }

    @GetMapping("/updateGuestroom")
    public String updateGuestroom(Guestroom guestroom) {
        if (guestroomMapper.updateGuestroom(guestroom) != 0) {
            return "updated";
        }
        return "error";
    }

    @GetMapping("/deleteGuestroom")
    public String deleteGuestroom(String roomno) {
        if (guestroomMapper.deleteGuestroom(roomno) != 0) {
            return "deleted";
        }
        return "error";
    }
}
